<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */ 

/**
 * Description of pagination
 *
 * @author IT
 */
class pagination extends db {
    function tachtrang()
    {
       $data = mysql_num_rows(mysql_query("SELECT * FROM articles"));
       $perpage = 2;
       if($data == 0)
       {
               $value = 1;
               echo "khong co bai viet<br><br>";
       }
       else {
            $value = ceil($data/$perpage);
           }
       if(isset($_GET['page']))
          $page = $_GET['page'];
       else {
          $page = 1;
       }
       //first
       $first = 1;
       echo '<li><a href ="index.php?page='.$first.'" class ="first">'.'First'.'</a></li>';
       
       //previous
       if($page > 1)
       {
           $previous = $page - 1;
            echo '<li><a href="index.php?page='.$previous.'" class ="previous">Previous</a></li>';
       }
       else
       {
           $previous = 1;
            echo '<li><a class ="'.'previous'.'">Previous</a></li>';
       }
       
        
       //page
       for($i = 1; $i <= $value;$i++)
       {
           if($page == $i)
               echo '<li><a><b>'.$i.'</b></a></li>';
           else
               echo '<li><a href="index.php?page='.$i.'">'.$i.'</a></li>';
       }
       
       //next
       if($page < $value)
       {
           $next = $page + 1;
           echo '<li><a href="index.php?page='.$next.'" class ="next">'.'Next'.'</a></li>';
       }
       else
       {
           $next = $page;
           echo '<li><a  class ="'.'next'.'">'.'Next'.'</a></li>';
       }
          
       
       
      //last
      
            $last = $value ;
            
                $last1 = '<li><a  href = "index.php?page='.$last.'" class="last">'.'Last'.'</a></li>';
           
       
            
       echo $last1;
    }
}
